package com.zh.note.huawei.onehundred.统计监控需要打开多少监控器;

import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/8/14 22:18
 * @description: create it
 */
public class Main {
    private static int rows = 0;
    private static int cols = 0;
    private static int[][] grid = new int[25][25];
    private static final int[][] DIRECTIONS = {{0, -1}, {0, 1}, {-1, 0}, {0, 0}};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        rows = sc.nextInt();
        cols = sc.nextInt();
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                grid[i][j] = sc.nextInt();
            }
        }
        int res = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (grid[i][j] == 1) {
                    res++;
                    continue;
                }
                //遍历相邻的格子
                if (i > 1 && grid[i - 1][j] == 1 ||
                        i < rows && grid[i + 1][j] == 1 ||
                        j > 1 && grid[i][j - 1] == 1 ||
                        j < cols && grid[i][j + 1] == 1 ||
                        grid[i][j] == 1
                ) {
                    res++;
                }
            }
        }
        System.out.println(res);
    }
}
